﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Seagull.BarTender.Print;
using System.Drawing.Printing;
using System.Threading;
using System.Collections;

namespace LabelPrint
{
    public partial class Form1 : Form
    {
        private bool isClosing = false; // 如果我们正在关闭，请设置为true。这有助于停止加载缩略图。
        private delegate void SetPos(int ipos);
        LabelFormatDocument btFormat;
       string DefaultPrinter1 ;
        private void SetTextMessage(int ipos)
        {
            if (this.InvokeRequired)
            {
                SetPos setpos = new SetPos(SetTextMessage);
                this.Invoke(setpos, new object[] { ipos });
            }
            else
            {
                this.label1.Text = ipos.ToString() + "/100";
                this.progressBar1.Value = Convert.ToInt32(ipos);
            }
        }
        //  第四步：函数实现
        private void progressClick()
        {
            Thread fThread = new Thread(new ThreadStart(SleepT));//开辟一个新的线程
            fThread.Start();
        }
        //  第五步：新的线程执行函数：
        private void SleepT()
        {
            for (int i = 0; i < 150; i++)
            {
                System.Threading.Thread.Sleep(100);//没什么意思，单纯的执行延时
                SetTextMessage(100 * i / 150);
            }
        }
        public Form1()
        {
            InitializeComponent();
        }
        SQLServerDataBase sql = new SQLServerDataBase();
        static DateTime vipTime;
        private Engine engine = null; // The BarTender Print Engine
        private void Form1_Load(object sender, EventArgs e)
        {

            string[] arr = new string[] { "P20","P25", "P50", "P60" };
            comboBox_packing.Items.AddRange(arr);



            string _connString = "server=192.168.2.99;database=admin;uid=sa;pwd=ljh6i22hc;";
            string getTime = "SELECT viptime FROM [dbo].[user] where id = 2";


           //读
            label7.Text = "使用时间:" + (vipTime - DateTime.Now).Days.ToString() + "天" + (vipTime - DateTime.Now).Hours.ToString() + "小时" + (vipTime - DateTime.Now).Minutes.ToString() + "分" + (vipTime - DateTime.Now).Seconds.ToString() + "秒";
            if (Convert.ToDateTime(sql.ExecuteSelectStr(getTime, _connString)) < DateTime.Now)
            {
                MessageBox.Show("打印服务组件试用到期，请重新联系IT获取使用权限");
                //    CanUse = false;
                this.Close();
                return;
            }
            try
            {
                engine = new Engine(true);
            }
            catch (PrintEngineException exception)
            {
                // If the engine is unable to start, a PrintEngineException will be thrown.
                MessageBox.Show(this, exception.Message);
                this.Close(); // Close this app. We cannot run without connection to an engine.
                return;
            }
            // 得到打印机列表
            Printers printers = new Printers();
            foreach (Printer printer in printers)
            {
                cboPrinters.Items.Add(printer.PrinterName);
            }

            // cboPrinters.SelectedItem = btFormat.PrintSetup.PrinterName;
            cboPrinters.SelectedItem = DefaultPrinter();
            DefaultPrinter1 = DefaultPrinter();
            //  textBox3.Text = DefaultPrinter();
        }
        string type = "RC";
        string spec = "0805";
        string quantity = "5000";
        string R_value = "3R10";
        string Packaging = "P";
        string lot = "2316B00254";//10位
        string u_int = "F";
        string Power = "1/16W";
        int P_index = 0;
        string getLabel = "RC 0603 J N 100R 101 2319E00386";
        // string name = "";

        string aa = "";
        string bb = "";
        string cc = "";
        string dd = "";
        string ee = "";
        private string ff;

        private void oneFunction()
        {
            string[] arr = new string[20];
            getLabel = textBox1.Text; // 获取扫出来的字
            string getlabelTemp = getLabel;
            // getLabel = getLabel.Replace(" ", "");//去空格

            arr = getLabel.Split(' ');

            u_int = arr[2];//精度

            int P_endIndex = getLabel.Length - 10;

            u_intRule();
            //type = getLabel.Substring(0, 2);
            type = arr[0];
            //  spec = getLabel.Substring(2, 4);
            spec = arr[1];
            if (spec == "2512" || spec == "2010")
            {
                P_index = getLabel.IndexOf("B", 7);
            }
            else
            {
                P_index = getLabel.IndexOf("P", 7);
            }
            //  R_value = getLabel.Substring(8, P_index - 8);
            R_value = arr[4];


            //  lot = getLabel.Substring(getLabel.Length - 10, 10);
            lot = arr[6];

            // Packaging = getLabel.Substring(P_index, P_endIndex - P_index);
            if (comboBox_packing.Text!=null)
            {
                Packaging = comboBox_packing.Text;
            }
            else
            {
                Packaging = getPack(spec);
            }
         
            //   label2.Text = Packaging;
            comboBox_packing.Text = Packaging;

            quantity = getQty(spec, Packaging);

            Power = getPower(type, spec);
            aa = R_value + "Ω±" + u_int;//zz + 精度
            bb = spec;//
            cc = Power;

            dd = quantity + "PCS";
            MessageBox.Show(dd);
            ee = lot;


            ff = arr[0] + arr[1] + arr[2] + " " + arr[3] + " " + arr[4] + " " + Packaging;

        }
        private int twoFunction(int total, out int box_count)
        {//盒标
            int boxNum;
            string[] arr = new string[20];
            getLabel = textBox1.Text; // 获取扫出来的字
            string getlabelTemp = getLabel;
            // getLabel = getLabel.Replace(" ", "");//去空格

            arr = getLabel.Split(' ');

            u_int = arr[2];//精度
            u_intRule();
            type = arr[0];
            spec = arr[1];
            if (spec == "2512" || spec == "2010")
            {
                P_index = getLabel.IndexOf("B", 7);
            }
            else
            {
                P_index = getLabel.IndexOf("P", 7);
            }

            R_value = arr[3];



            lot = arr[5];


            if (comboBox_packing.Text != null)
            {
                Packaging = comboBox_packing.Text;
            }
            else
            {
                Packaging = getPack(spec);
            }


            quantity = arr[4];

            Power = getPower(type, spec);
            aa = R_value + u_int;//zz + 精度
            bb = spec;//
            cc = Power;
            if (Packaging == "P25")
            {//求余
                box_count = 125;
                boxNum = total % box_count;
                dd = 125000 + "";//125K
            }         
            else if (spec == "0402" || spec == "0201")
            {//求余
                box_count = 250;
                boxNum = total % box_count;
                dd = 250000 + "";//250K
            }else
            {
                box_count = 100;
                boxNum = total % box_count;
                dd = 100000 +""; //100K   
            }

            ee = lot;
            ff = arr[0] + arr[1] + arr[2] + " N " + arr[3];
            gg = u_int;
          
            // RC 0402 F 0R11 5000 2323C00789 C00093 江山
            
            return boxNum;
        }
        private int thirdFunction(int total,out int box_count)//箱标
        {
            int boxNum;
            string[] arr = new string[20];
            getLabel = textBox1.Text; // 获取扫出来的字
            string getlabelTemp = getLabel;
            // getLabel = getLabel.Replace(" ", "");//去空格

            arr = getLabel.Split(' ');

            u_int = arr[2];//精度
            u_intRule();
            type = arr[0];
            spec = arr[1];
            if (spec == "2512" || spec == "2010")
            {
                P_index = getLabel.IndexOf("B", 7);
            }
            else
            {
                P_index = getLabel.IndexOf("P", 7);
            }

            R_value = arr[3];



            lot = arr[5];


            if (comboBox_packing.Text != null)
            {
                Packaging = comboBox_packing.Text;
            }
            else
            {
                Packaging = getPack(spec);
            }



            quantity = arr[4];

            Power = getPower(type, spec);
            aa = R_value + u_int;//zz + 精度
            bb = spec;//
            cc = Power;
            if (Packaging == "P25")
            {
                box_count = 625;
                boxNum = total % box_count;
                dd = 625 + "";//625K
            }

            else if (spec == "0402" || spec == "0201")
            {//求余
                box_count = 1250;
                boxNum = total % box_count;
                dd = 1250 + "";//1250K
            }
            else
            {
                box_count = 500;
                boxNum = total % box_count;
                dd = 500 + ""; //500K   
            }
           
            ee = lot;
            ff = arr[0] + arr[1] + arr[2] + " N " + arr[3];
            gg = u_int;
         //   jj = arr[0] + arr[1] + arr[2] + " " + arr[3];
            // RC 0402 F 0R11 5000 2323C00789 C00093 江山
            if (arr.Length >= 7)
            {
                hh = arr[6];
            }
            if (arr.Length >= 8)
            {
                ii = arr[7];
            }
            return boxNum;
        }

        private string getPack(string spec)
        {
            string packing = "";
            switch (spec)
            {
                case "0201":

                    packing = "P50";
                    break;
                case "0402":

                    packing = "P50";
                    break;
                case "0603":

                    packing = "P20";
                    break;
                case "0805":

                    packing = "P20";
                    break;
                case "1206":

                    packing = "P20";
                    break;
                default:
                    break;
            }
            return packing;
        }

        private void u_intRule()
        {
            if (u_int == "F")
            {
                u_int = "1%";
            }
            else
            {
                u_int = "5%";
            }
        }

        private string getPower(string type, string spec)
        {
            string power = "";
            switch (spec)
            {
                case "0201":
                    switch (type)
                    {
                        case "RC":
                            power = "1/20W";
                            break;
                        case "NQ":
                            power = "1/20W";
                            break;
                        case "HP":
                            power = " ";
                            break;
                        case "HV":
                            power = " ";
                            break;
                        case "HS":
                            power = "1/20W";
                            break;
                        case "AS":
                            break;
                        case "LE":
                            break;
                    }
                    break;
                case "0402":
                    switch (type)
                    {
                        case "RC":
                            power = "1/16W";
                            break;
                        case "NQ":
                            power = "1/16W";
                            break;
                        case "HP":
                            power = "1/10W";
                            break;
                        case "HV":
                            power = " ";
                            break;
                        case "HS":
                            power = "1/16W";
                            break;
                        case "AS":
                            break;
                        case "LE":
                            break;
                    }
                    break;
                case "0603":
                    switch (type)
                    {
                        case "RC":
                            power = "1/10W";
                            break;
                        case "NQ":
                            power = "1/10W";
                            break;
                        case "HP":
                            power = "1/5W";
                            break;
                        case "HV":
                            power = "1/10W";
                            break;
                        case "HS":
                            power = "1/10W";
                            break;
                        case "AS":
                            power = "1/4W";
                            break;
                        case "LE":
                            power = "1/10W";
                            break;
                    }
                    break;
                case "0805":
                    switch (type)
                    {
                        case "RC":
                            power = "1/8W";
                            break;
                        case "NQ":
                            power = "1/8W";
                            break;
                        case "HP":
                            power = "1/3W";
                            break;
                        case "HV":
                            power = "1/8W";
                            break;
                        case "HS":
                            power = "1/8W";
                            break;
                        case "AS":
                            power = "1/2W";
                            break;
                        case "LE":
                            power = "1/8W";
                            break;
                    }
                    break;
                case "1206":
                    switch (type)
                    {
                        case "RC":
                            power = "1/4W";
                            break;
                        case "NQ":
                            power = "1/4W";
                            break;
                        case "HP":
                            power = "1/2W";
                            break;
                        case "HV":
                            power = "1/4W";
                            break;
                        case "HS":
                            power = "1/4W";
                            break;
                        case "AS":
                            power = "0.6W";
                            break;
                        case "LE":
                            power = "1/4W";
                            break;
                    }
                    break;
                case "1210":
                    switch (type)
                    {
                        case "RC":
                            power = "1/2W";
                            break;
                        case "NQ":
                            power = "1/2W";
                            break;
                        case "HP":
                            power = "3/4W";
                            break;
                        case "HV":
                            power = "1/2W";
                            break;
                        case "HS":
                            power = "1/2W";
                            break;
                        case "AS":
                            power = "3/4W";
                            break;
                        case "LE":
                            power = "";
                            break;
                    }
                    break;
                case "2010":
                    switch (type)
                    {
                        case "RC":
                            power = "3/4W";
                            break;
                        case "NQ":
                            power = "3/4W";
                            break;
                        case "HP":
                            power = "1W";
                            break;
                        case "HV":
                            power = "3/4W";
                            break;
                        case "HS":
                            power = "3/4W";
                            break;
                        case "AS":
                            power = "1.5W";
                            break;
                        case "LE":
                            power = "";
                            break;
                    }
                    break;
                case "2512":
                    switch (type)
                    {
                        case "RC":
                            power = "1W";
                            break;
                        case "NQ":
                            power = "1W";
                            break;
                        case "HP":
                            power = "2W";
                            break;
                        case "HV":
                            power = "1W";
                            break;
                        case "HS":
                            power = "1W";
                            break;
                        case "AS":
                            power = "2W";
                            break;
                        case "LE":
                            power = "";
                            break;
                    }
                    break;
            }
            return power;
        }
        private string getQty(string spec, string packaging)
        {
           // 0402 每卷是50K，每盒是250K，0603 / 0805 / 1206每卷是20K，每盒是100K
            string qty = "";
            switch (spec)
            {
                case "0201":
                    if (packaging == "P")
                    {
                        qty = "15000";
                    }
                    else if (packaging == "P20")
                    {
                        qty = "20000";
                    }
                    else if (packaging == "P25")
                    {
                        qty = "25000";
                    }
                    else if(packaging == "P50")
                    {
                        qty = "50000";
                    }
                    else if (packaging == "P60")
                    {
                        qty = "60000";
                    }
                    break;

                case "0402":
                    if (packaging == "P")
                    {
                        qty = "10000";
                    }
                    else if (packaging == "P20")
                    {
                        qty = "20000";
                    }
                    else if (packaging == "P25")
                    {
                        qty = "25000";
                    }
                    else if (packaging == "P50")
                    {
                        qty = "50000";
                    }
                    else if (packaging == "P60")
                    {
                        qty = "60000";
                    }
                    break;

                case "0603":
                    if (packaging == "P")
                    {
                        qty = "5000";
                    }
                    else if (packaging == "P20")
                    {
                        qty = "20000";
                    }
                    else if (packaging == "P25")
                    {
                        qty = "25000";
                    }
                    else if (packaging == "P50")
                    {
                        qty = "50000";
                    }
                    else if (packaging == "P60")
                    {
                        qty = "60000";
                    }
                    break;

                case "0805":
                    if (packaging == "P")
                    {
                        qty = "5000";
                    }
                    else if (packaging == "P20")
                    {
                        qty = "20000";
                    }
                    else if (packaging == "P25")
                    {
                        qty = "25000";
                    }
                    else if (packaging == "P50")
                    {
                        qty = "50000";
                    }
                    else if (packaging == "P60")
                    {
                        qty = "60000";
                    }
                    break;

                case "1206":
                    if (packaging == "P")
                    {
                        qty = "5000";
                    }
                    else if (packaging == "P20")
                    {
                        qty = "20000";
                    }
                    else if (packaging == "P25")
                    {
                        qty = "25000";
                    }
                    else if (packaging == "P50")
                    {
                        qty = "50000";
                    }
                    else if (packaging == "P60")
                    {
                        qty = "60000";
                    }
                    break;

                case "1210":
                    if (packaging == "P")
                    {
                        qty = "5000";
                    }
                    else if (packaging == "P20")
                    {
                        qty = "20000";
                    }
                    else if (packaging == "P25")
                    {
                        qty = "25000";
                    }
                    else if (packaging == "P50")
                    {
                        qty = "50000";
                    }
                    else if (packaging == "P60")
                    {
                        qty = "60000";
                    }
                    break;

                

                case "2010":
                    if (packaging == "B")
                    {
                        qty = "4000";
                    }

                    break;

                case "2512":
                    if (packaging == "B")
                    {
                        qty = "4000";
                    }
                    break;
                default:
                    break;
            }
            return qty;
        }

        private static PrintDocument fPrintDocument = new PrintDocument();

        private string gg;
        private string hh;
        private string ii;
        private int PrinterFlag = 0;

        public string jj;

        //获取本机默认打印机名称
        public static String DefaultPrinter()
        {
            return fPrintDocument.PrinterSettings.PrinterName;
        }

        private void button1_Click(object sender, EventArgs e)
        {//打印与模板路径问题，默认路径是我开发电脑上的模板路径,RC 0402 F N 0R11 P 2323C00789|RC 0402 F 0R11 5000 2323C00789
            int total = Convert.ToInt32(textBox_total.Text.ToString());//总数
            int copies = total*1000 / Convert.ToInt32(quantity);//总数除以每盘的数量，得到 盘数50k / 5k = 10

            oneFunction();
      
                printBtw("newSbq.txt", textBox2.Text);     //  根据总数计算出份数
          

        }

        /// <summary>
        /// 按需求打印
        /// </summary>
        /// <param name="FieldPath">模板名称</param>
        /// <param name="btw_path">模板路径</param>
        /// <param name="Copie">份数</param>
        /// <param name="remain">余数</param>
        void printBtw(string FieldPath, string btw_path,int Copie,int remain)
        { 
            lock (engine)
            {
                if (remain != 0)
                {
                    if (PrinterFlag==2)
                   {
                    dd = remain.ToString() + "000";
                   }
                else
                   {
                   
                    dd = remain.ToString() + "";
                   
                   }
                }

                string path = AppDomain.CurrentDomain.BaseDirectory;
                string serialNumber = "resistance|size|wattage|quantity|lot_no|item_name|u_int|type|R_value|Packaging|addr|customer_name\r\n" + aa + "|" + bb + "|" + cc + "|" + dd + "|" + ee + "|" + ff + "|" + gg + "|" + type + "|" + R_value + "|" + Packaging + "|" + hh + "|" + ii;
                using (StreamWriter stream = new StreamWriter(path + "\\" + FieldPath))
                {
                    stream.Write(serialNumber);
                }
                //Lable 路径 

                string filePath = path + btw_path + ".btw";
                btFormat = engine.Documents.Open(filePath);
                //如何传参 命名具名数据源 赋予对应的 key<>value
                //          btFormat.SubStrings["ProductName"].Value = “test1”;
                //传入打印机名称
                btFormat.PrintSetup.PrinterName = cboPrinters.SelectedItem.ToString();
                //打印张数
                btFormat.PrintSetup.IdenticalCopiesOfLabel = Copie;
                //     MessageBox.Show("开始打印");
                // btFormat.Print("UID Printing Job", 10000);//如果打不出来可能是软件安装不正确导致，重新安装可能会解决此问题
                Messages messages;
                string appName = "下标打印任务";
                Result result = btFormat.Print(appName, 10000, out messages);
                string messageString = "\n\nMessages:";

                foreach (Seagull.BarTender.Print.Message message in messages)
                {
                    messageString += "\n\n" + message.Text;
                }

                if (result == Result.Failure)
                {
                    MessageBox.Show(this, "警告" + messageString, appName);
                }

                else
                {
                    //MessageBox.Show(this, "文本已成功发送到打印机" + messageString, appName);
                }

            }





        }

        void printBtwCS(string FieldPath, string btw_path)
        {
            lock (engine)
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
              
                //Lable 路径 

                string filePath = path + btw_path + ".btw";
                btFormat = engine.Documents.Open(filePath);
                //如何传参 命名具名数据源 赋予对应的 key<>value
                //          btFormat.SubStrings["ProductName"].Value = “test1”;
                //传入打印机名称
                btFormat.PrintSetup.PrinterName = cboPrinters.SelectedItem.ToString();
                //打印张数
                btFormat.PrintSetup.IdenticalCopiesOfLabel = Convert.ToInt32(textBox4.Text.ToString());
                //     MessageBox.Show("开始打印");

                Messages messages;
                string appName = "下标打印任务";
                Result result = btFormat.Print(appName, 10000, out messages);
                string messageString = "\n\nMessages:";

                foreach (Seagull.BarTender.Print.Message message in messages)
                {
                    messageString += "\n\n" + message.Text;
                }

                if (result == Result.Failure)
                    MessageBox.Show(this, "Print Failed" + messageString, appName);
                else
                    MessageBox.Show(this, "文本已成功发送到打印机" + messageString, appName);
            }

            //btFormat.Close(SaveOptions.DoNotSaveChanges);
            //    engine.Stop();
            //}



        }

        void printBtw(string FieldPath, string btw_path)
        {
            lock (engine)
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string serialNumber = "resistance|size|wattage|quantity|lot_no|item_name|u_int|addr|customer_name\r\n" + aa + "|" + bb + "|" + cc + "|" + dd + "|" + ee + "|" + ff + "|" + gg + "|" + hh + "|" + ii;
                using (StreamWriter stream = new StreamWriter(path + "\\" + FieldPath))
                {
                    stream.Write(serialNumber);
                }
                //Lable 路径 

                string filePath = path + btw_path + ".btw";
                 btFormat = engine.Documents.Open(filePath);
                //如何传参 命名具名数据源 赋予对应的 key<>value
                //          btFormat.SubStrings["ProductName"].Value = “test1”;
                //传入打印机名称
                btFormat.PrintSetup.PrinterName = cboPrinters.SelectedItem.ToString();
                //打印张数
                btFormat.PrintSetup.IdenticalCopiesOfLabel = Convert.ToInt32(textBox4.Text.ToString());
                //     MessageBox.Show("开始打印");
             
                Messages messages;
                string appName = "下标打印任务";
                Result result = btFormat.Print(appName, 10000, out messages);
                string messageString = "\n\nMessages:";

                foreach (Seagull.BarTender.Print.Message message in messages)
                {
                    messageString += "\n\n" + message.Text;
                }

                if (result == Result.Failure)
                    MessageBox.Show(this, "Print Failed" + messageString, appName);
                else
                    MessageBox.Show(this, "文本已成功发送到打印机" + messageString, appName);
            }

            //btFormat.Close(SaveOptions.DoNotSaveChanges);
            //    engine.Stop();
            //}



        }

        private void button2_Click(object sender, EventArgs e)
        {//RC 0402 F N 0R11 P 5000 2323C00789 盒标
         //盒标，假设每盒500k,总量1020，打3盒，2盒500，1盒20
            PrinterFlag = 2;
            int box_count;
            int total = Convert.ToInt32(textBox_total.Text.ToString());
            int boxNum = twoFunction(total,out box_count);//求余
         
            if (boxNum > 0)
            {//有余数，多打一箱，数量为余数

                if (total < box_count)//总数小于每箱数
                {
                    printBtw("BoxLabel.txt", textBox5.Text, 1, boxNum);
                }
                else
                {
                    printBtw("BoxLabel.txt", textBox5.Text, (total - boxNum) / box_count, 0);//打整数部分
                    printBtw("BoxLabel.txt", textBox5.Text, 1, boxNum);//打余数部分
                }
              
            }
            else
            {//整数就打箱数
                printBtw("BoxLabel.txt", textBox5.Text,total/ box_count, 0);
            }

          
        
        }

        private void button3_Click(object sender, EventArgs e)
        {//RC 0402 F N 0R11 P 5000 2323C00789 箱标
         //箱标的数量标准是，根据订单总数进行拆解，0402每箱是1250K，0603 / 0805 / 1206每箱是500K
            PrinterFlag = 3;
            //  Thread td = new Thread(() => printBtw("XiangLabel.txt", textBox6.Text));//开辟一个新的线程       
            //  td.Start();
            int box_count;
            int total = Convert.ToInt32(textBox_total.Text.ToString());
            int moreBoxNum = thirdFunction(total,out box_count); //余数

            if (moreBoxNum > 0)
            {//有余数，多打一箱，数量为余数

                if (total < box_count)//总数小于每箱数，直接打一箱
                {
                    printBtw("XiangLabel.txt", textBox6.Text, 1, moreBoxNum);
                }
                else
                {
                    printBtw("XiangLabel.txt", textBox6.Text, (total - moreBoxNum) / box_count, 0);
                    printBtw("XiangLabel.txt", textBox6.Text, 1, moreBoxNum);
                }
              
            }
            else
            {//整数就打箱数
                printBtw("XiangLabel.txt", textBox6.Text, total / box_count, 0);
            }


         //   printBtw("XiangLabel.txt", textBox6.Text);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (engine != null)
                engine.Stop(SaveOptions.DoNotSaveChanges);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            new LabelPrint().Show();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //  关闭bartender进程

            if (engine != null)
                engine.Stop(SaveOptions.DoNotSaveChanges);
        }

        private void button5_Click(object sender, EventArgs e)
        {
          //  printBtw("BoxLabel.txt", textBox5.Text, 1, boxNum);/
              printBtwCS("CaseLabel.txt", textBox5.Text);
        }
    }
}
